/**
 * tjftp -- A simple FTP server, using the ANSI C
 * Copyright (C) 2011  degui.chen <degui.chen@qq.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include "unity.h"
#include <unistd.h>
#include <errno.h>


void _tj_debug_log(char* result, char* file, char* fun, int line, int ansi_c) {
	printf("debug[%i] : %-80s - %s:(%s,%i), ANSI C: %i \n", getpid(), result, file, fun, line, ansi_c);
}

void tj_print_usage() {
	printf("Usage: cat [OPTION]... [FILE]...\n");
	printf("Concatenate FILE(s), or standard input, to standard output.\n");
	printf("\n");
	printf("  -e                       equivalent to -vE\n");
	printf("  -h                       equivalent to -vE\n");
	printf("  -v                       equivalent to -vE\n");
	printf("\n");
	printf("Examples:\n");
	printf("  cat f - g  Output f's contents, then standard input, then g's contents.\n");
}

int tj_epoll_receive(int accept_fd, char result[], int res_len) {
	int revc_len = read(accept_fd, result, res_len);
	if (revc_len < 0) {
		if (errno == ECONNRESET) {// for epoll 客户端重新连接
			return -1; //用于关闭 accept_fd
		}
	}
	result[revc_len] = '\0';
	return revc_len;
}
